<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      * {
        margin: 0;
        padding: 0;
        list-style: none;
      }
      .list {
        position: relative;
        border: 1px solid #ddd;
        width: 400px;
      }
      body {
        height: 10000px;
      }
      .list li {
        position: absolute;
        display: flex;
        justify-content: center;
        align-items: center;
        top: 250px;
        left: 50px;
        width: 100px;
        height: 100px;
        background-color: green;
      }
      .list .b {
        background-color: gold;
        top: 500px;
      }

      .list .c {
        background-color: aqua;
        top: 750px;
      }

      .list .d {
        top: 750px;
        background-color: orange;
      }
    </style>
  </head>
  <body>
    <ul class="list">
      <li class="a">a</li>
      <li class="b">b</li>
      <li class="d">d</li>
      <li class="c">c</li>
    </ul>
    <script type="module">
      import gsap from "../_snowpack/pkg/gsap.js";
      import { ScrollTrigger } from "../_snowpack/pkg/gsap/ScrollTrigger.js";
      gsap.registerPlugin(ScrollTrigger);

      const tl = gsap.timeline({
        scrollTrigger: {
          trigger: ".c",
          start: "top center",
          end: "top 200px",
          markers: true,
          scrub: 3,
          toggleActions: "restart pause reverse pause",
        },
      });

      tl.to(".c", {
        x: 400,
        rotation: 360,
        ease: "none",
        duration: 3,
      })
        .to(".c", {
          backgroundColor: "purple",
          duration: 1,
        })
        .to(".c", {
          x: 0,
          duration: 3,
        });

      gsap.to(".d", {
        scrollTrigger: {
          trigger: ".d",
          pin: true,
          start: "top center+=200",
          end: "top 200px",
          markers: true,
          scrub: true,
          toggleActions: "restart pause reverse pause",
        },
        x: 400,
        rotation: 360,
        ease: "none",
        duration: 3,
      });
    </script>
  </body>
</html>
